package com.bot.nft.core.config;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.bot.common.exception.CommonException;
import com.bot.dev.api.DevConfigApi;

/**
 * 描述:
 * 时间: 2024-01-30 20:38
 * 负责人: 王速
 **/
public class BlockchainUtil {

    //获取项目名称
    private static final String BOTIAN_BLOCKCHAIN_WENCHANG_PROJECT_NAME_KEY = "BOTIAN_BLOCKCHAIN_WENCHANG_PROJECT_NAME";
    //获取域名
    private static final String BOTIAN_BLOCKCHAIN_WENCHANG_DNS_KEY = "BOTIAN_BLOCKCHAIN_WENCHANG_DNS";
    //获取 API Key
    private static final String BOTIAN_BLOCKCHAIN_WENCHANG_APIKEY_KEY = "BOTIAN_BLOCKCHAIN_WENCHANG_APIKEY";
    //获取API Secret
    private static final String BOTIAN_BLOCKCHAIN_WENCHANG_APISECRET_KEY = "BOTIAN_BLOCKCHAIN_WENCHANG_APISECRET";
    //获取链上账户名
    private static final String BOTIAN_BLOCKCHAIN_WENCHANG_ACCOUNT_NAME_KEY = "BOTIAN_BLOCKCHAIN_WENCHANG_ACCOUNT_NAME";

    //获取链上地址
    private static final String BOTIAN_BLOCKCHAIN_WENCHANG_ADDRESS_KEY = "BOTIAN_BLOCKCHAIN_WENCHANG_ADDRESS";

    static DevConfigApi devConfigApi =  SpringUtil.getBean(DevConfigApi.class);


    /**
     * 获取项目名称
     * @return
     */
    public static String getProjectName() {
        /* 获取项目名称 */
        String accessKeyName = devConfigApi.getValueByKey(BOTIAN_BLOCKCHAIN_WENCHANG_PROJECT_NAME_KEY);
        if (ObjectUtil.isEmpty(accessKeyName)) {
            throw new CommonException("文昌链未正确配置：项目名称为空");
        }
        return accessKeyName;
    }

    /**
     * 获取域名
     */
    public static  String  getDns(){
        String accessKeyDns = devConfigApi.getValueByKey(BOTIAN_BLOCKCHAIN_WENCHANG_DNS_KEY);

        if (ObjectUtil.isEmpty(accessKeyDns)) {
            throw new CommonException("文昌链未正确配置：域名为空");
        }
        return accessKeyDns;
    }

    /**
     * 获取 API Key
     */
    public static  String  getApiKey(){
        String apiKey = devConfigApi.getValueByKey(BOTIAN_BLOCKCHAIN_WENCHANG_APIKEY_KEY);

        if (ObjectUtil.isEmpty(apiKey)) {
            throw new CommonException("文昌链未正确配置：API Key为空");
        }
        return apiKey;
    }

    /**
     *  获取API Secret
     */
    public static  String  getApiSecret(){
        String apiSecret = devConfigApi.getValueByKey(BOTIAN_BLOCKCHAIN_WENCHANG_APISECRET_KEY);

        if (ObjectUtil.isEmpty(apiSecret)) {
            throw new CommonException("文昌链未正确配置：ApiSecret为空");
        }
        return apiSecret;
    }

    /**
     *  获取链上账户名
     */
    public static  String getAccount(){
        String account = devConfigApi.getValueByKey(BOTIAN_BLOCKCHAIN_WENCHANG_ACCOUNT_NAME_KEY);

        if (ObjectUtil.isEmpty(account)) {
            throw new CommonException("文昌链未正确配置：链上账户名为空");
        }
        return  account;
    }

    /**
     *  获取链上地址
     */
    public static  String getAddress(){
        String account = devConfigApi.getValueByKey(BOTIAN_BLOCKCHAIN_WENCHANG_ADDRESS_KEY);

        if (ObjectUtil.isEmpty(account)) {
            throw new CommonException("文昌链未正确配置：链上地址为空");
        }
        return  account;
    }

}
